import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


public class DataLoader {
    public static Map<String, Teacher> loadTeachers(String FilePath) {
        Map<String, Teacher> teachers = new HashMap<>();
        try (BufferedReader reader = new BufferedReader(new FileReader(FilePath + "teachers.txt"))) {
            String line;
            while ((line = reader.readLine()) != null) {
                String[] parts = line.split(",");
                teachers.put(parts[0], new Teacher(parts[0], parts[1], parts[2], parts[3], parts[4],Integer.parseInt(parts[5])));

            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return teachers;
    }

    public static Map<String, Student> loadStudents(String FilePath) {
        Map<String, Student> students = new HashMap<>();
        try (BufferedReader reader = new BufferedReader(new FileReader(FilePath + "students.txt"))) {
            String line;
            while ((line = reader.readLine()) != null) {
                String[] parts = line.split(",");
                students.put(parts[0], new Student(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5]));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return students;
    }

    public static Map<String, Course> loadCourses(String FilePath) {
        Map<String, Course> courses = new HashMap<>();
        try (BufferedReader reader = new BufferedReader(new FileReader(FilePath + "courses.txt"))) {
            String line;
            while ((line = reader.readLine()) != null) {
                String[] parts = line.split(",");
                courses.put(parts[0], new Course(parts[0], parts[1], Integer.parseInt(parts[2]), Double.parseDouble(parts[3]), parts[4], parts[5], parts[6], parts[7], parts[8]));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return courses;
    }

    public static Map<String, Classroom> loadClassrooms(String FilePath) {
        Map<String, Classroom> classrooms = new HashMap<>();
        try (BufferedReader reader = new BufferedReader(new FileReader(FilePath + "classrooms.txt"))) {
            String line;
            while ((line = reader.readLine()) != null) {
                String[] parts = line.split(",");
                classrooms.put(parts[0], new Classroom(parts[0], parts[1], Integer.parseInt(parts[2])));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return classrooms;
    }

    public static ArrayList loadEnrollments(String FilePath) {
        ArrayList<Enrollment> enrollments = new ArrayList<>();
        try (BufferedReader reader = new BufferedReader(new FileReader(FilePath + "enrollments.txt"))) {
            String line;
            while ((line = reader.readLine()) != null) {
                String[] parts = line.split(",");
                enrollments.add(new Enrollment(parts[0], parts[1], parts[2], Double.parseDouble(parts[3]), parts[4], parts[5]));
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return enrollments;
    }
    public static Map<String, Class> loadClass(String FilePath) {
        Map<String, Class> classes = new HashMap<>();
        try (BufferedReader reader = new BufferedReader(new FileReader(FilePath + "classes.txt"))) {
            String line;
            while ((line = reader.readLine())!= null) {
                String[] parts = line.split(",");
                classes.put(parts[0], new Class(parts[0], parts[1]));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return classes;
    }
    public static Map<String, stucoursemsg> loadStucoursemsg(String FilePath) {
        Map<String, stucoursemsg> stucoursemsgs = new HashMap<>();
        try (BufferedReader reader = new BufferedReader(new FileReader(FilePath + "stucoursemsgs.txt"))) {
            String line;
            while ((line = reader.readLine())!= null) {
                String[] parts = line.split(",");
                stucoursemsgs.put(parts[0], new stucoursemsg(parts[0], parts[1], parts[2]));
            }
        }catch (IOException e) {
            e.printStackTrace();
        }
        return stucoursemsgs;
    }
}



